package yur.wedding.modules.sys.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import yur.wedding.common.utils.Query;

import yur.wedding.modules.sys.dao.SysRoleDoorDao;
import yur.wedding.modules.sys.entity.SysRoleDoorEntity;
import yur.wedding.modules.sys.service.SysRoleDoorService;
import yur.wedding.utils.PageUtils;


@Service("sysRoleDoorService")
public class SysRoleDoorServiceImpl extends ServiceImpl<SysRoleDoorDao, SysRoleDoorEntity> implements SysRoleDoorService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SysRoleDoorEntity> page = this.page(
                new Query<SysRoleDoorEntity>().getPage(params),
                new QueryWrapper<SysRoleDoorEntity>()
        );

        return new PageUtils(page);
    }


    /**
     * 门户权限添加  修改  方法共用
     *
     * @param doorId
     * @param doorIdList
     */
    @Override
    public void saveOrUpdate(Long doorId, List<Long> doorIdList) {
        //先删除之前有的
        deleteBatch(new Long[]{doorId});
        if (doorIdList.size() > 0) {
            for (Long ls : doorIdList) {
                SysRoleDoorEntity entity = new SysRoleDoorEntity();
                entity.setDoorId(ls);
                entity.setRoleId(doorId);
                this.save(entity);
            }
        }
        return;
    }

    /**
     * 查询角色对应的门户
     * @param role_id
     * @return
     */
    @Override
    public List<Long> queryDoorIdList(Long role_id) {


        return baseMapper.queryDoorIdList(role_id);
    }

    private void deleteBatch(Long[] longs) {

        baseMapper.deleteBatch(longs);
    }

}
